﻿using System.Security.Claims;

namespace WebService.Models
{
    public class CommonAuthUser
    {
        public long Id { get; set; }
        public string Name { get; set; }
        public IdentityType Type { get; set; }
        public string Role { get; set; }

        public int PId { get; set; }

        public string StationId { get; set; }

        public DateTime? ExpireDate { get; set; }

        public ICollection<Claim> CreateMainClaims()
        {
            return new List<Claim>
            {
                new Claim(ClaimTypes.NameIdentifier, Id.ToString()),
                new Claim(ClaimTypes.Name, Name ?? ""),
                new Claim(ClaimTypes.Version, ((int)Type).ToString()),
                new Claim(ClaimTypes.Role, Role ?? ""),
            };
        }

        public virtual ICollection<Claim> CreateOtherClaims()
        {
            return new List<Claim>
            {
                new Claim(ClaimTypes.PrimarySid, PId.ToString()),
                new Claim(ClaimTypes.Sid, StationId?.ToString() ?? string.Empty),
            };
        }

        public long? GetMediaEndId()
        {
            long? result = Type switch
            {
                IdentityType.Platform or IdentityType.System or IdentityType.Customer => Id,
                _ => (long?)PId,
            };
            return result;
        }

    }
}
